package com.example.waterorder.controller;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class RabbitMqListener {
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "user.queue"),
            exchange = @Exchange(name = "order.exchange", type = ExchangeTypes.DIRECT),
            key = "user"
    ))

    public void listenUserQueue(String msg) {
        System.out.println("消费者接收到user.queue的消息：【" + msg + "】");
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "worker.queue"),
            exchange = @Exchange(name = "order.exchange", type = ExchangeTypes.DIRECT),
            key = "worker"
    ))
    public void listenWorkerQueue(String msg) {
        System.out.println("消费者接收到worker.queue的消息：【" + msg + "】");
    }


    //    @RabbitListener(queues = "simple.queue")
    public void listenSimpleQueueMessage(String msg) throws InterruptedException {
        System.out.println("spring 消费者接收到消息：【" + msg + "】");
    }
}
